import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;


public class Main {
	
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int testCases = Integer.parseInt(br.readLine().trim());
		while(testCases-- != 0) {
			int length = Integer.parseInt(br.readLine().trim());
			String str = br.readLine();
			StringTokenizer sToken = new StringTokenizer(str, " ");
			
			List<Stick> sticks = new ArrayList<Main.Stick>();
			for(int i = 0; i < length; i++) {
				sticks.add(new Stick(Integer.parseInt(sToken.nextToken()), 
						Integer.parseInt(sToken.nextToken())));
			}
			
			Collections.sort(sticks);
			List<List<Stick>> l = new ArrayList<List<Stick>>();
			for(int i = 0; i < length; i++) {
				Stick currentStick = sticks.get(i);
				boolean matchFound = false;
				for(int j = 0; j < l.size(); j++) {
					Stick lastStick = l.get(j).get(l.get(j).size() - 1);
					
					if (currentStick.l <= lastStick.l && currentStick.w <= lastStick.w) {
						l.get(j).add(currentStick);
						matchFound = true;
						break;
					}
				}
				if(!matchFound) {
					List<Stick> n = new ArrayList<Main.Stick>();
					n.add(currentStick);
					l.add(n);
				}
			}

			System.out.println(l.size());
		}
	}
	
	private static class Stick implements Comparable<Stick> {
		int l, w;
		
		private Stick(int l, int w) {
			this.l = l;
			this.w = w;
		}

		@Override
		public int compareTo(Stick o) {
			return o.l*o.w - this.l*this.w;
		}
		
		public String toString() {
			return l + " " + w;
		}
	}

}

